<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="关联状态" prop="state">
        <el-select
          v-model="queryParams.state"
          placeholder="请选择关联状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.user_correlate_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="问诊状态" prop="state">
        <el-select
          v-model="queryParams.state2"
          placeholder="请选择问诊状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.treatment_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否作废" prop="state">
        <el-select
          v-model="queryParams.state3"
          placeholder="请选择是否作废"
          clearable
        >
          <el-option
            v-for="dict in dict.type.register_yuyue_del"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否挂起" prop="state">
        <el-select
          v-model="queryParams.state4"
          placeholder="请选择是否挂起"
          clearable
        >
          <el-option
            v-for="dict in dict.type.suspended_or_not"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="缴费状态" prop="state">
        <el-select
          v-model="queryParams.state5"
          placeholder="请选择是否挂起"
          clearable
        >
          <el-option
            v-for="dict in dict.type.patient_money_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="关联时间">
        <el-date-picker
          v-model="daterangeTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="重症患者" prop="registerId">
        <el-select
          v-model="queryParams.registerId"
          placeholder="请选择患者姓名"
          clearable
        >
          <el-option
            v-for="item in yuyueList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="患者电话" prop="registerId">
        <el-select
          v-model="queryParams.registerId"
          placeholder="请选择患者电话"
          clearable
        >
          <el-option
            v-for="item in yuyueList"
            :key="item.id"
            :label="item.phone"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="问诊医生" prop="doctorId">
        <el-select
          v-model="queryParams.doctorId"
          placeholder="请选择问诊医生"
          clearable
        >
          <el-option
            v-for="item in doctorList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="检查项目" prop="projectId">
        <el-select
          v-model="queryParams.projectId"
          placeholder="请选择检查项目"
          clearable
        >
          <el-option
            v-for="item in projectList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['patient:patientInfo:add']"
          >新增住院人员
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd2"
          v-hasPermi="['patient:patientInfo:add']"
          >新增重病人员
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['patient:patientInfo:edit']"
          >修改</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['patient:patientInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['patient:patientInfo:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="patientInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="关联状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.user_correlate_status"
            :value="scope.row.state"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="患者id 外键关联患者" align="center" prop="registerId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.registerId"/>
        </template>
      </el-table-column>
      <el-table-column label="关联医生id外键关联医生" align="center" prop="doctorId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.doctorId"/>
        </template>
      </el-table-column>
      <el-table-column label="检查项目id外键关联检查项目" align="center" prop="projectId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_job_status" :value="scope.row.projectId"/>
        </template>
      </el-table-column> -->

      <el-table-column label="关联编号" align="center" prop="register.id" />
      <el-table-column label="患者姓名" align="center" prop="register.name" />
      <el-table-column label="性别" align="center" prop="register.sex">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_user_sex"
            :value="scope.row.register.sex"
          />
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="register.age" />
      <el-table-column label="头像" align="center" prop="registerId">
        <template slot-scope="scope">
          <image-preview
            :src="scope.row.register.img"
            :width="50"
            :height="50"
          />
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" prop="register.phone" />
      <!--
            scope.row  当前这一行的对象
      -->
      <!-- <el-table-column
        label="检查科室"
        align="center"
        prop="register.departmentId"
      >
        <template slot-scope="scope">
          {{ deparvalue[scope.row.register.departmentId] }}
        </template>
      </el-table-column> -->
      <el-table-column
        label="检查科室"
        align="center"
        prop="register.departmentId"
      >
        <template slot-scope="scope">
          <span v-for="item in departmentList" :key="item.id">
            <span v-if="item.id == scope.row.register.departmentId">
              {{ item.name }}
            </span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="大夫" align="center" prop="doctor.name" />
      <el-table-column label="检查项目" align="center" prop="project.name" />
      <el-table-column label="问诊费用" align="center">
        <!-- 在这里计算费用合并 -->
        <template slot-scope="scope">
          <span>{{ scope.row.project.money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="关联时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['patient:patientInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['patient:patientInfo:remove']"
            >删除</el-button
          > -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="lookPatientInfo(scope.row)"
            v-hasPermi="['patient:patientInfo:list']"
            >患者详情
          </el-button>
          <el-button
            v-if="scope.row.state == 1"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleUpdate2(scope.row)"
            v-hasPermi="['patient:patientInfo:edit']"
            >关联医生
          </el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-s-claim"
            @click="handleTotal(scope.row)"
            v-hasPermi="['discharge:discharge:remove']"
            >消费单</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改患者列表对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择关联状态">
            <el-option
              v-for="dict in dict.type.user_correlate_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="患者id 外键关联患者" prop="registerId">
          <el-select
            v-model="form.registerId"
            placeholder="请选择患者id 外键关联患者"
          >
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联医生id外键关联医生" prop="doctorId">
          <el-select
            v-model="form.doctorId"
            placeholder="请选择关联医生id外键关联医生"
          >
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检查项目id外键关联检查项目" prop="projectId">
          <el-select
            v-model="form.projectId"
            placeholder="请选择检查项目id外键关联检查项目"
          >
            <el-option
              v-for="dict in dict.type.sys_job_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联时间" prop="time">
          <el-date-picker
            clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择关联时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="逻辑删除" prop="del">
          <el-radio-group v-model="form.del">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->

    <!-- 添加或修改病房列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="患者姓名" prop="patientId">
          <el-select
            v-model="form.patientId"
            placeholder="请选择要住院的重症患者姓名"
          >
            <el-option
              v-for="dict in yuyueList"
              :key="dict.id"
              :label="dict.name"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="病房" prop="wardId">
          <el-select v-model="form.wardId" placeholder="请选择病房">
            <el-option
              v-for="dict in wardList"
              :key="dict.id"
              :label="dict.wardnum"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="住院时间" prop="creatTime">
          <el-date-picker
            clearable
            v-model="form.creatTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择住院时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入院病因" prop="disease">
          <el-input v-model="form.disease" placeholder="请输入入院病因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改大夫对话框 -->
    <el-dialog
      :title="title2"
      :visible.sync="open2"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="大夫" prop="doctorId">
          <el-select v-model="form.doctorId" placeholder="请选择大夫">
            <el-option
              v-for="item in doctorList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="关联时间" prop="time">
          <el-date-picker
            clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择住院时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改预约对话框 -->
    <el-dialog
      :title="title2"
      :visible.sync="open3"
      width="700px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- 第一行: 预约时间和就诊科室 -->
        <el-row :gutter="20">
          <!-- 第一行: 预约时间和就诊卡号 -->
          <el-col :span="12">
            <el-form-item label="预约时间" prop="registTime">
              <el-date-picker
                clearable
                v-model="form.registTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择预约时间"
                :picker-options="pickerOptions0"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就诊卡号" prop="clinicCard">
              <el-input
                v-model="form.clinicCard"
                placeholder="请输入就诊卡号"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="就诊科室" prop="departmentId">
              <el-select v-model="form.departmentId" placeholder="请选择科室">
                <el-option
                  v-for="item in departmentList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  {{ item.name }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就诊医生" prop="doctorId">
              <el-select
                v-model="form.doctorId"
                placeholder="请选择医生"
                :disabled="isInClass"
              >
                <el-option
                  v-for="item in doctorList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                  v-if="item.departmentId == form.departmentId"
                >
                  {{ item.name }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第三行: 就诊姓名和就诊性别 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="form.sex">
                <el-radio
                  v-for="dict in dict.type.sys_user_sex"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第四行: 身份证号和就诊年龄 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="身份证号" prop="identityCard">
              <el-input
                v-model="form.identityCard"
                placeholder="请输入身份证号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input-number
                v-model="form.age"
                controls-position="right"
                :min="0"
                :max="150"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第五行: 手机号码和所属民族 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属民族" prop="nation">
              <el-select
                v-model="form.nation"
                placeholder="请选择所属民族"
                clearable
              >
                <el-option
                  v-for="dict in dict.type.people_ethnic_ffiliation"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第六行: 联系地址 -->
        <el-form-item label="联系地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入联系地址" />
        </el-form-item>
        <el-form-item label="预约渠道" prop="appointmentWay">
          <el-radio-group v-model="form.appointmentWay">
            <el-radio
              v-for="dict in dict.type.user_channel_status"
              :key="dict.value"
              :label="dict.value"
            >
              {{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="图片" prop="img">
          <image-upload v-model="form.img" />
        </el-form-item>

        <!-- 第七行: 门诊编号和住院编号 -->
        <!-- <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="门诊编号" prop="outpatientId">
              <el-input
                v-model="form.outpatientId"
                placeholder="请输入门诊编号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住院编号" prop="admissionId">
              <el-input
                v-model="form.admissionId"
                placeholder="请输入住院编号"
              />
            </el-form-item>
          </el-col>
        </el-row> -->

        <!-- 第八行: 医保性质和医保卡号 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="医保性质" prop="nature">
              <!-- <el-input v-model="form.nature"  style="width: 220px" placeholder="请输入医保性质"/> -->
              <el-radio-group v-model="form.nature">
                <el-radio
                  v-for="dict in dict.type.patient_medical_status"
                  :key="dict.value"
                  :label="dict.value"
                >
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="医保卡号" prop="cardnumber">
              <el-input
                v-model="form.cardnumber"
                placeholder="请输入医保卡号"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第八行: 医保性质和医保卡号 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="检查项目" prop="projectId">
              <el-select v-model="form.projectId" placeholder="请选择检查项目">
                <el-option
                  v-for="item in projectList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  {{ item.name }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm2">确认添加</el-button>
      </div>
    </el-dialog>

    <!-- 查看消费单对话框 -->
    <!-- Dialog -->
    <el-dialog title="消费单详情" :visible.sync="dialogVisible" width="50%">
      <div class="custom-descriptions-container">
        <div class="custom-descriptions-item">
          <span class="label">挂号费用：{{ patientCurrentMoney }}</span>
        </div>
        <div class="custom-descriptions-item">
          <span class="label">总费用：</span>
          <span class="value">{{ patientCurrentMoney }}元</span>
        </div>
        <!-- 其他费用项类似 -->
        <div>
          <el-button type="primary" @click="goPay" v-if="isPay == false"
            >去支付</el-button
          >
          <el-button type="success" v-else>已支付</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPatientInfo,
  getPatientInfo,
  delPatientInfo,
  addPatientInfo,
  updatePatientInfo,
} from "@/api/patient/patientInfo";
import { listYuyue, addYuyue } from "@/api/register/yuyue";
import { listDoctor } from "@/api/doctor/doctor";
import { listProject } from "@/api/treatment/project";
import { listDepartment } from "@/api/department/department";
import { addPatient } from "@/api/patient/patient";
import { listWard } from "@/api/ward/ward";
import { addDischarge } from "@/api/discharge/discharge";
// 	引入支付
import { pay, ispay } from "@/api/discharge/pay";

export default {


  name: "PatientInfo",
  dicts: [
    // 字典数组
    "sys_job_status",
    "sys_yes_no",
    "user_correlate_status",
    "treatment_status",
    "register_yuyue_del",
    "suspended_or_not",
    "patient_money_status",
    "people_ethnic_ffiliation",
    "sys_user_sex",
    "user_channel_status",
    "patient_medical_status",
  ],
  data() {
    
    return {

      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;//如果没有后面的-8.64e7就是不可以选择今天的
        }
      },


      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 患者列表表格数据
      patientInfoList: [],
      // 弹出层标题
      title: "",
      title2: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      // 逻辑删除时间范围
      daterangeTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        state: null, // 关联状态
        state2: null, // 问诊状态
        state3: null, // 是否作废
        state4: null, // 是否挂起
        state5: null, // 缴费状态
        registerId: null,
        doctorId: null,
        projectId: null,
        time: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      // 检查项目列表
      projectList: [],
      // 预约列表
      yuyueList: [],
      // 医生列表
      doctorList: [],

      // 科室对象
      deparvalue: {},
      // 科室数组
      departmentList: [],

      // 病房列表
      wardList: [],
      patientCurrentId: "", //	当前消费单的患者id
      patientCurrentMoney: "", //	当前消费单的金额
      isPay: false, //	是否已付费
      dialogVisible: false, //	控制消费单显示隐藏
    };
  },
  computed: {
    isInClass() {
      return this.form.departmentId == null;
    },
  },
  // 页面一加载 立即执行的函数
  created() {
    this.getList();
    this.getYuList();
    this.getDocterList();
    this.getProjectList();
    this.getDepartmentList();
    this.getWardList();

    console.log(this.yuyueList);
  },
  methods: {
    // 支付功能
    //	去支付的方法
    //	去支付的方法
    // goPay() {
    //   pay(this.patientCurrentId, this.patientCurrentMoney)
    //     .then((res) => {
    //       var payGatewayHtml = res; // 假设这是返回的HTML表单字符串

    //       // 创建一个新的窗口（或标签页）
    //       var newWindow = window.open("", "_blank");

    //       // 如果新窗口被阻止，则处理错误情况
    //       if (
    //         !newWindow ||
    //         newWindow.closed ||
    //         typeof newWindow.closed == "undefined"
    //       ) {
    //         alert("新窗口被阻止，请允许弹出窗口以继续支付。");
    //         return;
    //       }

    //       // 写入表单HTML到新窗口的文档中
    //       newWindow.document.write(payGatewayHtml);

    //       // 由于document.write是同步的，我们可以立即关闭写入流
    //       newWindow.document.close();

    //       // 注意：通常不需要手动提交表单，因为表单HTML可能已经包含了自动提交的逻辑（如onsubmit事件）
    //       // 如果需要手动提交，并且表单有唯一的ID或可以通过其他方式选择，你可以在新窗口的文档中查找并提交它
    //       // 例如：var form = newWindow.document.getElementById('paymentForm'); form.submit();
    //       // 但这通常不是必需的，除非支付网关有特定的要求
    //     })
    //     .catch((error) => {
    //       console.error("支付请求失败:", error);
    //     });
    // },
    // // 消费单按钮操作
    // handleTotal(row) {
    //   this.loading = true;
    //   console.log("aaaaaa" + row.projectId);
    //   //	获取当前患者id用作付费商品单号，金额用作转账额度
    //   this.patientCurrentId = row.projectId;
    //   this.patientCurrentMoney = row.project.money;

    //   //	判断是否已经付过钱
    //   ispay(this.patientCurrentId).then((response) => {
    //     if (response == "10000") {
    //       console.log(response);

    //       console.log(this.isPay);
    //       this.$router.push({ path: "/patient/patientInfo" });
    //     } else {
    //       console.log("还没付过钱");
    //     }
    //   });
    //   this.loading = false;
    //   this.dialogVisible = true;
    // },

    /** 查询ward列表 */
    getWardList() {
      this.loading = true;
      listWard(this.queryParams).then((response) => {
        this.wardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查看患者详情 */
    lookPatientInfo(row) {
      // 页面跳转
      this.$router.push({
        path: "/patient/patientInfo/PatientDetails",
        query: { register: row.register },
      });
    },

    /** 获取查询检查项目列表 */
    getProjectList() {
      this.loading = true;
      listProject(this.queryParams).then((response) => {
        this.projectList = response.rows;
      });
    },

    /** 获取查询医生列表列表 */
    getDocterList() {
      this.loading = true;
      listDoctor(this.queryParams).then((response) => {
        this.doctorList = response.rows;
      });
    },

    /** 获取查询预约列表 */
    getYuList() {
      this.loading = true;
      listYuyue(this.queryParams).then((response) => {
        this.yuyueList = response.rows;
      });
    },

    /** 查询科室管理列表 */
    getDepartmentList() {
      this.loading = true;
      listDepartment(this.queryParams).then((response) => {
        this.departmentList = response.rows;
        // 遍历集合
        for (var i = 0; i < this.departmentList.length; i++) {
          this.$set(
            this.deparvalue,
            this.departmentList[i].id,
            this.departmentList[i].name
          );
        }
      });
    },

    /** 查询患者列表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeTime && "" != this.daterangeTime) {
        this.queryParams.params["beginTime"] = this.daterangeTime[0];
        this.queryParams.params["endTime"] = this.daterangeTime[1];
      }
      listPatientInfo(this.queryParams).then((response) => {
        this.patientInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open2 = false;
      this.open3 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        state: null,
        registerId: null,
        doctorId: null,
        projectId: null,
        time: null,
        del: null,
        patientId: null,
        status: null,
        costTotal: null,
        departmentId: null,
        patientCurrentId: "",
        patientCurrentMoney: "",
        isPay: false,
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getYuList();
      this.getDocterList();
      this.getProjectList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      // 调用
      this.reset();
      this.open = true;
      this.title = "添加患者列表";
    },
    handleAdd2() {
      // 调用
      this.reset();
      this.open3 = true;
      this.title = "添加患者列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPatientInfo(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改患者列表";
      });
    },
    /** 修改关联信息操作 */
    handleUpdate2(row) {
      row.status = 1;
      this.reset();
      const id = row.id || this.ids;
      getPatientInfo(id).then((response) => {
        this.form = response.data;
        this.open2 = true;
        this.title2 = "修改关联信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            // 修改关联状态
            this.form.state = 0;
            updatePatientInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.open2 = false;
              this.open3 = false;
              this.getList();
              this.getYuList();
              this.getDocterList();
              this.getProjectList();
              this.getDepartmentList();
              this.getWardList();
            });
          } else {
            // 向住院表添加数据
            addPatient(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              console.log("aaaa" + this.form.patientId);
              this.open = false;
              this.open2 = false;
              this.open3 = false;
              this.getList();
              this.getYuList();
              this.getDocterList();
              this.getProjectList();
              this.getDepartmentList();
              this.getWardList();
            });

            // 同时向出院表添加数据
            let aa = {
              status: 1,
              patientId: this.form.patientId,
              costTotal: this.form.costTotal,
              del: this.form.del,
            };
            addDischarge(aa).then((response) => {
              console.log("哈哈哈" + response);
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.open2 = false;
              this.open3 = false;
              this.getList();
              this.getYuList();
              this.getDocterList();
              this.getProjectList();
              this.getDepartmentList();
              this.getWardList();
            });
          }
        }
      });
    },

    // 提交按钮2
    submitForm2() {
      addYuyue(this.form).then((response) => {
        const patientId = response.data.id;
        const doctorId = this.form.doctorId;
        const projectId = this.form.projectId;
        this.$modal.msgSuccess("新增成功");
        this.open3 = false;
        this.getList();
        console.log(patientId);
        let aa = {
          state:1,
          registerId: patientId,
          doctorId: doctorId,
          projectId: projectId,
        };
        // 同时向自己表添加数据
        addPatientInfo(aa).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open3 = false;
          location.reload();
          this.getList();
        });
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除患者列表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delPatientInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "patient/patientInfo/export",
        {
          ...this.queryParams,
        },
        `patientInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
